<template>
  <div class="container">
    <div class='login_content'>
      <div class='user_photo'><open-data type="userAvatarUrl"></open-data></div>
      <div class='user_nickname' style="color: white"><open-data type="userNickName"></open-data></div>
      <form class="login_btn" report-submit='true'>
        <button  form-type='submit' open-type="getUserInfo" @click="bindGetUserInfo" style="background-color: #f0860b">登录</button>
      </form>
      <!-- <button @click="navigateToHome">返回首页</button> -->
      <div class="desc">
          <p>人工智能党建助手手机端介绍：</p>
          <p>1、参与内部会议</p>
          <p>2、手机同步PPT内容</p>
          <p>3、参与会议讨论</p>
      </div>
    </div>
  </div>
</template>
<script>
import { postCode } from '../../api/index.js'
import { mapActions } from 'vuex'

export default {
  data () {
    return {
    }
  },
  methods: {
    ...mapActions(['_reqUserInfo']),
    bindGetUserInfo(e){
      var This = this;
      let code = this.$store.state.userCode;
      uni.getUserProfile({
        lang : 'zh_CN',
          desc: '获取您的昵称和头像信息',
        success : res => {
          This.$store.dispatch('_setWXUserInfo',res); //将用户信息保存的VUEX
          let parmas = {
            raw_data:res.rawData,
            signature:res.signature,
            code:code
          };
          //发送code到服务器获取数据
          postCode(parmas).then(respones => {
            if(respones.data.level=="success"){
              uni.setStorageSync('userToken',respones.data.data);
              uni.navigateBack({
                  delta:1
              })
              // uni.redirectTo({
              //   url:"/pages/home/home"
              // })
							// if(uni.getStorageSync('type') == 'host'){
							// 	uni.redirectTo({
							// 	  url:"/pages/host/host"
							// 	})
							// }else{
							// 	uni.redirectTo({
							// 	  url:"/pages/attendee/attendee"
							// 	})
							// }
            }else{
              uni.showToast(respones.data.message,'none',1000)
            }
          })
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.container{
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #d90913;
  .login_content{
    width: 70%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    top: -100rpx;
    .desc{
      color: white;
      margin-top: 30px;

      p{
        padding-left: 10px;
        padding-top: 5px;
        font-size: 0.8rem;
      }
    }
    .login_btn{
      width: 100%;
    }
    .user_photo{
      width: 150rpx;
    }
    .user_nickname{
      text-align: center;
      margin-top: 20px;
    }
    button{
      font-size: 14px;
      margin-top: 30rpx;
      border-radius: 10rpx;
      width: 54%;
      background-color: green;
      color: #fff;
    }
  }
}
</style>
